//
//  DUListItem.m
//  APP
//
//  Created by duyujin1 on 2021/8/1.
//

#import "DUListItem.h"

@implementation DUListItem

#pragma mark -NSSecureCoding

//设置key
- (nullable instancetype)initWithCoder:(NSCoder *)coder{
    if(self=[super init]){
        self.url=[coder decodeObjectForKey:@"url"];
        self.source=[coder decodeObjectForKey:@"source"];
        self.replyCount=[coder decodeObjectForKey:@"replyCount"];
        self.mtime=[coder decodeObjectForKey:@"mtime"];
        self.imgsrc=[coder decodeObjectForKey:@"imgsrc"];
        self.title=[coder decodeObjectForKey:@"title"];
        self.sourceId=[coder decodeObjectForKey:@"uniqueKey"];
    }
    return self;
}

//序列化方法
- (void)encodeWithCoder:(NSCoder *)coder{
    [coder encodeObject:self.url forKey:@"url"];
    [coder encodeObject:self.source forKey:@"source"];
    [coder encodeObject:self.replyCount forKey:@"replyCount"];
    [coder encodeObject:self.mtime forKey:@"mtime"];
    [coder encodeObject:self.imgsrc forKey:@"imgsrc"];
    [coder encodeObject:self.title forKey:@"title"];
    [coder encodeObject:self.sourceId forKey:@"uniqueKey"];
}

+(BOOL)supportsSecureCoding{
    return YES;
}


#pragma mark -public method

-(void) configWithDictionary:(NSDictionary *) dictionary{
    
#warning 类型是否匹配
    self.replyCount=[dictionary objectForKey:@"replyCount"];
    self.imgsrc=[dictionary objectForKey:@"imgsrc"];
    self.sourceId=[dictionary objectForKey:@"sourceId"];
    self.title=[dictionary objectForKey:@"title"];
    self.mtime=[dictionary objectForKey:@"mtime"];
    self.source=[dictionary objectForKey:@"source"];
    self.url=[dictionary objectForKey:@"url"];
}

@end
